package cn.itcast.hotel.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {
    /**
     * 构建自定义的线程池
     *
     * @param poolProperties
     * @return
     */
    @Bean
    public ThreadPoolExecutor myThreadPool(ThreadPoolProperties poolProperties) {
        System.out.println("=========执行了");
        return new ThreadPoolExecutor(
                poolProperties.getCorePoolSize(),
                poolProperties.getMaximumPoolSize(),
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(poolProperties.getQueueNum()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    @Bean
    public RestHighLevelClient client() {
        return new RestHighLevelClient(RestClient.builder(
//                华为云
                HttpHost.create("http://113.45.170.115:9200")));
    }
}
